package leetcode.easy;

import java.util.Deque;
import java.util.LinkedList;

/**
 * ClassName: MinStack
 * Description:
 * date: 2022-02-18 23:26
 *
 * @author liyifan
 */
public class MinStack {
    private Deque<Integer> stack;
    private Deque<Integer> minStack;
    public MinStack() {
        stack = new LinkedList<>();
        minStack = new LinkedList<>();
        minStack.push(Integer.MAX_VALUE);
    }

    public void push(int val) {
        minStack.push(Math.min(val, getMin()));
        stack.push(val);
    }

    public void pop() {
        minStack.pop();
        stack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
